<template>
    <div class="jobcommon EditResumeInfo">
        <div class="smalbox">
            <div class="backnavjob">
                <h1 @click="closejibenxinxi('close')">
                    <img
                        data-v-61dd7a3d=""
                        src="../../assets//newimg/index/icon_right_h.png"
                        alt=""
                    />
                </h1>
                <h2>
                    <span>简历-特长标签</span>
                </h2>
                <h3></h3>
            </div>

            <div class="edittag" style="overflow: hidden">
                <div class="tit font12">最多可以选5项</div>
                <div id="J_tagWrap">
                    <div class="J_tagPage">
                        <div
                            class="tag"
                            :class="{ select: item.key }"
                            v-for="(item, index) in tagsData"
                            :key="index"
                            @click="checkbiaoqin(item.id)"
                        >
                            {{ item.name }}
                        </div>
                    </div>
                </div>
                <div class="clear"></div>
            </div>

            <div class="j_newbutton" style="margin-top: 1rem">
                <div class="j_newbtn" @click="closejibenxinxi()">保存</div>
            </div>
            <div class="zhanwei"></div>
        </div>
    </div>
</template>

<script>
import { axiosPost } from '../../axios';
import { Toast } from 'vant';
export default {
    name: '',
    props: ['tags', 'checktag', 'pid'],
    data() {
        return {
            tagsData: [],
            overCHeck: [],
        };
    },
    computed: {},
    mounted() {
        this.tagsData = [];
        for (let i in this.tags) {
            let data = {
                id: i,
                name: this.tags[i],
                key: false,
            };
            for (let k in this.checktag) {
                if (i == k) {
                    data.key = true;
                }
            }
            this.tagsData.push(data);
        }
    },
    methods: {
        closejibenxinxi(type) {
            if (type) {
                this.$emit('closeProps', { type: 9, key: false });
                return;
            }
            this.overCHeck = [];
            this.tagsData.forEach((el) => {
                if (el.key) {
                    this.overCHeck.push(el.id);
                }
            });
            if (this.overCHeck.length == 0) {
                return Toast({
                    message: '请选择标签',
                    duration: 2000,
                });
            }
            axiosPost(
                '/apis/resume/edit_speciality',
                {
                    tag: this.overCHeck.map((option) => option).join(','),
                    pid: this.pid,
                },
                (res) => {
                    Toast({
                        message: res.msg,
                        duration: 2000,
                    });
                    if (res.status != 1) {
                        return;
                    }
                    this.$emit('closeProps', { type: 9, key: true });
                }
            );
        },
        checkbiaoqin(id) {
            this.tagsData.map((el) => {
                if (el.id == id) {
                    el.key = !el.key;
                }
                return el;
            });
        },
    },
};
</script>
<style lang="less" src="../../assets/css/jobCommon.less" scope></style>
<style lang="less" scope></style>
